use std::io;
use std::cmp::Ordering;
use rand::Rng;

fn main() {
    print!("guess number.\n");

    let secret = rand::thread_rng().gen_range(1..101);
    print!("secret is {}\n",secret);

    loop{

        let mut guess = String::new();

        io::stdin()
        .read_line(&mut guess)
        .expect("fail read.\n");

        /* so called shadowing */
        let guess:u32 = match guess.trim().parse(){
            Ok(num) => num,
            Err(_) => {
                print!("not a number.\n");
                continue;
            }
        };

        match guess.cmp(&secret) {
            Ordering::Equal  => {
                print!("equal.\n");
                break;
            }

            Ordering::Greater =>{
                print!("Greater.\n");
            }

            Ordering::Less => {
                print!("Less. \n")
            }
        };
        print!("You are guessing {0}\n",guess);
    }
    print!("loopout\n");
    return;
}
